package com.tbm.console.proj.controller;

import com.alibaba.fastjson.JSONArray;
import com.tbm.console.base.controller.BaseController;
import com.tbm.console.common.constant.ConsoleConstant;
import com.tbm.console.proj.entity.ReportConfigInfoEntity;
import com.tbm.console.proj.service.ReportConfigInfoService;
import com.tbm.console.util.JurisdictionUtil;
import com.tbm.console.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

//说明 字符串：ReportConfigInfo，作为替换字符串

@Controller
public class ReportConfigInfoController extends BaseController {

    @Autowired
    private ReportConfigInfoService reportConfigInfoService;

    /**
     * 系统管理--报表配置
     *
     * @return
     */
    @RequestMapping("/admin-report-manage")
    public ModelAndView adminListManage() {

        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if (JurisdictionUtil.isValid()) {
            viewName = "reportConfigInfo/reportConfigInfo-list";
            List<ReportConfigInfoEntity> all = reportConfigInfoService.findAll();
            PageData result = new PageData();
            String host = "";
            String port = "";
            String path = "";
            String firstParam = "";
            if(all.size()==1){
                ReportConfigInfoEntity entity = all.get(0);
                host = entity.getHost();
                port = String.valueOf(entity.getPort());
                path = entity.getPath();
                firstParam = entity.getFirstParam();
            }
            result.put("host",host);
            result.put("port",port);
            result.put("path",path);
            result.put("firstParam",firstParam);
            modelAndView.addObject("report", result);
        }
        modelAndView.setViewName(viewName);
        return modelAndView;
    }

    /**
     * 常量维护
     * @return
     */
    @RequestMapping("/reportConfigInfo-list")
    public ModelAndView listManage(){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            viewName = "reportConfigInfo/reportConfigInfo-manage";
            Object attribute = this.getRequest().getSession().getAttribute(ConsoleConstant.BTNRIGHTS);
            List<PageData> buttonList = (List<PageData>) JSONArray.parse(attribute.toString());
            modelAndView.addObject("buttons", buttonList);
        }
        modelAndView.setViewName(viewName);
        return modelAndView;
    }
}